
export default class ValueWrapper {
  constructor(valuePar) {
    this.value = valuePar;
    this.time = Date.now();
  }

  getValue() {
    return this.value;
  }

  setValue(value) {
    this.value = value;
  }

  getType() {
    return this.type;
  }

  setType(t) {
    this.type = t;
  }

  getTime() {
    return this.time;
  }

  setTime(time) {
    this.time = time;
  }

  static isIntegral(primitive) {
    const numberStr = primitive.toString();
    return Number.isInteger(Number(numberStr));
  }

  static isInteger(primitive) {
    const numberStr = primitive.toString();
    return !numberStr.includes(".") && !numberStr.toLowerCase().includes("e");
  }

  static StructValueWrapper = class extends ValueWrapper {
    constructor(valueParam = {}) {
      super(valueParam);
      this.type = "struct";
    }

    addValue(key, valueWrapper) {
      if (!this.value) {
        this.value = {};
      }
      this.value[key] = valueWrapper;
    }

    getValue() {
      return this.value;
    }

    setValue(valueList) {
      this.value = valueList;
    }
  };

  static ArrayValueWrapper = class extends ValueWrapper {
    constructor(valueParam = []) {
      super(valueParam);
      this.type = "array";
    }

    getValue() {
      return this.value;
    }

    add(obj) {
      if (!this.value) {
        this.value = [];
      }
      this.value.push(obj);
    }

    setValue(valueParam) {
      this.value = valueParam;
    }
  };

  static DoubleValueWrapper = class extends ValueWrapper {
    constructor(valueParam) {
      super(valueParam);
      this.type = "double";
    }

    getValue() {
      return this.value;
    }

    setValue(valueParam) {
      this.value = valueParam;
    }
  };

  static BooleanValueWrapper = class extends ValueWrapper {
    constructor(valueParam) {
      super(valueParam);
      this.type = "bool";
    }
  };

  static StringValueWrapper = class extends ValueWrapper {
    constructor(valuePar) {
      super(valuePar);
      this.type = "string";
    }

    getValue() {
      return this.value;
    }

    setValue(value) {
      this.value = value;
    }
  };

  static EnumValueWrapper = class extends ValueWrapper {
    constructor(valuePar) {
      super(valuePar);
      this.type = "enum";
    }
  };

  static DateValueWrapper = class extends ValueWrapper {
    constructor(valuePar) {
      super(valuePar);
      this.type = "date";
    }
  };

  static IntValueWrapper = class extends ValueWrapper {
    constructor(valueParam) {
      super(valueParam);
      this.type = "int";
    }

    getValue() {
      return this.value;
    }

    setValue(value) {
      this.value = value;
    }
  };
}
